layui.use(['form', 'layer'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    $.ajax({
        url: $.cookie("tempUrl") + "umsmemberdoctor/findUmsMemberDoctorDetailsVO?memberId=" + $.cookie("tempId"),
        type: "POST",
        success: function (result) {
            if (result.code === 200) {
                $(".name").val(result.data.name);
                $(".gender").val(result.data.gender===1?"男":"女");
                $(".age").val(result.data.age);
                $(".pastMedicalHistory").val(result.data.pastMedicalHistory);
                $(".historyDrugAllergy").val(result.data.historyDrugAllergy);
                $(".bq").val(result.data.bq);
                $(".phone").val(result.data.phone);
                $(".phone").val(result.data.phone);




                form.render();
            } else {
                layer.msg(result.exception, {icon: 7, anim: 6});
            }
        }
    });


    form.on("submit(submit)", function (data) {
        layer.confirm('修改信息将会被重新审核，是否确认?', {title: '系统提示', area: ['320px', '200px']}, function (index0) {
            //do something
            //弹出loading
            const index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            $.ajax({
                url: $.cookie("tempUrl") + "hSysDoctor/updateByPrimaryKeySelective",
                type: "PUT",
                datatype: "application/json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({
                    id: $.cookie("doctorId"),
                    // icon: coverUrl,
                    icon: coverUrl,
                    nickname: data.field.username,
                    sex: data.field.sex,
                    phone: data.field.phone,
                    doctorTitleId: data.field.doctorTitleId,
                    deptId: data.field.deptId
                }),
                success: function (result) {
                    if (result.code === 200) {
                        layer.msg("更新成功");
                        $.cookie('icon', coverUrl, {path: '/'});
                        setTimeout(function () {
                            top.layer.close(index);
                            // top.layer.msg("新增成功2");
                            layer.closeAll("iframe");
                            //刷新本页面
                            location.reload();
                        }, 500);
                    } else {
                        layer.msg('更新异常', {icon: 7, anim: 6});
                    }
                }
            });

            layer.close(index);
        });
        return false;
    });
});